package com.daylightrobbery.server.entity;

import com.daylightrobbery.server.packet.game.GamePrepareDataPacket;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

public class Room {
    private static AtomicInteger roomIdGenerator = new AtomicInteger(100000);;
    private boolean status; //是否游戏中
    private Integer roomId;
    private String roomName;
    private String roomOwnerUid;
    private ConcurrentHashMap<String, PlayerInfo> players;
    private GamePrepareDataPacket packet;


    public GamePrepareDataPacket getPacket() {
        return packet;
    }

    public Room setPacket(GamePrepareDataPacket packet) {
        this.packet = packet;
        return this;
    }

    public Room(){
        roomId = roomIdGenerator.getAndIncrement();
        players = new ConcurrentHashMap<>();
    }

    public Integer getRoomId() {
        return roomId;
    }

    public Room setRoomId(Integer roomId) {
        this.roomId = roomId;
        return this;
    }

    public String getRoomName() {
        return roomName;
    }

    public Room setRoomName(String roomName) {
        this.roomName = roomName;
        return this;
    }

    public String getRoomOwnerUid() {
        return roomOwnerUid;
    }

    public Room setRoomOwnerUid(String roomOwnerUid) {
        this.roomOwnerUid = roomOwnerUid;
        return this;
    }

    public ConcurrentHashMap<String, PlayerInfo> getPlayers() {
        return players;
    }

    public Room addPlayers(PlayerInfo player){
        players.put(player.getUid(), player);
        return this;
    }

    public boolean isStatus() {
        return status;
    }

    public Room setStatus(boolean status) {
        this.status = status;
        return this;
    }

    @Override
    public String toString() {
        return "Room{" +
                "status=" + status +
                ", roomId=" + roomId +
                ", roomName='" + roomName + '\'' +
                ", roomOwnerUid='" + roomOwnerUid + '\'' +
                ", players=" + players +
                ", packet=" + packet +
                '}';
    }
}
